#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 55;
struct node
{
	int a, b, c;
}S[N];
int n;
int cmp(node a, node b)
{
	return a.b > b.b;
}
int main()
{
	int t;
	cin >> t;
	while (t--) {
		cin >> n;
		memset(S, 0, sizeof(S));
		for (int i = 0; i < n; i++) {
			int a, b;
			cin >> a >> b;
			S[i] = { a,b,i + 1 };
		}
		sort(S, S + n, cmp);
		int idx = 0;
		for (int i = 0; i < n; i++) {
			if (S[i].a <= 10) {
				idx = S[i].c;
				break;
			}
		}
		cout << idx << endl;
	}
	return 0;
}